/*
 * @lc app=leetcode.cn id=77 lang=cpp
 *
 * [77] 组合
 */

// @lc code=start
class Solution
{
private:
    vector<int> path;
    vector<vector<int>> res;
    int index = 1;
    void backtracking(int n, int k, int index)
    {
        //返回条件 如果path大小达到k加入res然后返回
        if (path.size() == k)
        {
            res.push_back(path);
            return;
        }
        for (int i = index; i <= n; i++)
        {
            path.push_back(i);
            backtracking(n, k, i + 1);
            path.pop_back();
        }
    }

public:
    vector<vector<int>> combine(int n, int k)
    {
        //回溯法学习
        backtracking(n, k, index);
        return res;
    }
};
// @lc code=end

